var __extends = this.__extends || function (d, b) {
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};
var KanbanDashBoard = (function (_super) {
    __extends(KanbanDashBoard, _super);
    function KanbanDashBoard() {
        _super.apply(this, arguments);

    }
    KanbanDashBoard.prototype.Ready = function () {
        $.templates({
            KPITemplate: "#KPITemplate",
            ProjectsTemplate: "#ProjectsTemplate",
            KPIProjectsTemplate: "#KPIProjectsTemplate",
            PopOverTemplate: "#PopOverTemplate"
        });
        this.BugsList();
        this.KPIProjects();
        this.KanbanProject();
        $('html,.moreInfo').click(function (e) {
            $('.moreInfo').popover('hide');
        });
    };
    KanbanDashBoard.prototype.BugsList = function () {
        var _this = this;
        $.getJSON(this.aUrl[0], null, function (data) {
            $("#keypointsdiv").html($.render.KPITemplate(data.kpi));
            _this.InitGraph(data.BugItems.FixedBugs, data.BugItems.NewBugs, 'Fixed', 'New', 'bugGraph', 'Bugs History', 250, false);
            window.setTimeout(function () {
                return _this.BugsList();
            }, 240000);
        });
    };
    KanbanDashBoard.prototype.KanbanProject = function () {
        var self = this;
        $.getJSON(self.aUrl[1], null, function (data) {
            $("#wilist").html($.render.ProjectsTemplate(data.Iterations));
            if(data.KanbanIpMax != -1) {
                $("#kanbanipmax").empty().text('(' + data.KanbanIpMax + ')');
            }
            if(data.KanbanTtMax != -1) {
                $("#kanbanttmax").empty().text('(' + data.KanbanTtMax + ')');
            }
            $(".moreInfo").popover({
                html: true,
                placement: "left",
                title: "Items list",
                content: function () {
                    var element = $(this);
                    var div_id = "div-id-" + $.now();
                    $.getJSON(self.aUrl[3], {
                        iteration: element.attr('data-id'),
                        state: element.attr('data-col')
                    }, function (data) {
                        $('#' + div_id).html($.render.PopOverTemplate(data));
                    });
                    return ('<ul class="sppop" id="' + div_id + '">Loading...</ul>');
                },
                trigger: 'manual'
            }).click(function (e) {
                $(this).popover('toggle');
                e.stopPropagation();
            });
            window.setTimeout(function () {
                return Base.Page.Self.KanbanProject();
            }, 300000);
        });
    };
    KanbanDashBoard.prototype.KPIProjects = function () {
        var _this = this;
        $.getJSON(this.aUrl[2], null, function (data) {
            $("#KPIProjects").html($.render.KPIProjectsTemplate(data.Totals));
            _this.InitGraph(data.HistoryDone, null, null, null, 'gphTasksDone', 'Tasks done (by day)', 160, true);
            _this.InitGraph(data.HistoryHoursCompleted, null, null, null, 'gphHoursDone', 'Hours done (by day)', 160, true);
            _this.InitGraph(data.HistoryUsDone, null, null, null, 'gphUsDone', 'User Stories done (by day)', 160, true);
            window.setTimeout(function () {
                return _this.KPIProjects();
            }, 360000);
        });
    };
    KanbanDashBoard.prototype.InitGraph = function (serie1, serie2, serie1Name, serie2Name, renderName, title, height, smallLabel) {
        var series = Array();
        if(serie1) {
            series.push({
                name: serie1Name,
                data: serie1
            });
        }
        if(serie2) {
            series.push({
                name: serie2Name,
                data: serie2
            });
        }
        if(series && series.length > 0) {
            var legend = series.length > 1;
            var xAxis = {
                categories: [
                    'D-6', 
                    'D-5', 
                    'D-4', 
                    'D-3', 
                    'D-2', 
                    'D-1', 
                    'Today'
                ],
                labels: {
                    rotation: -45,
                    align: 'right'
                }
            };
            var myTitle = {
                text: title
            };
            if(smallLabel) {
                xAxis.labels.style = {
                    fontSize: '8px'
                };
                myTitle.style = {
                    fontSize: '14px'
                };
            }
            this.bdgchart = new Highcharts.Chart({
                chart: {
                    renderTo: renderName,
                    height: height,
                    borderRadius: 0,
                    backgroundColor: '#FFF',
                    type: 'column'
                },
                legend: {
                    enabled: legend
                },
                credits: {
                    enabled: false
                },
                colors: [
                    '#00AEEF', 
                    '#E23300'
                ],
                xAxis: xAxis,
                yAxis: {
                    min: 0,
                    title: {
                        text: null
                    }
                },
                title: myTitle,
                series: series
            });
        }
    };
    return KanbanDashBoard;
})(Base.Page);
//@ sourceMappingURL=KanbanDashBoard.js.map
